import * as userApi from '@/api/user.js';
export default {
  namespaced: true,
  state() {
    return {
      info: localStorage.getItem('userInfo') || {},
    };
  },
  mutations: {
    SET_INFO(state, newValue) {
      state.info = newValue;
    },
  },
  actions: {
    async login({ commit }, params) {
      const pageRes = {
        success: true,
        msg: '',
      };
      await userApi.login(params)
        .then((res) => {
          pageRes.msg = res.result.msg;
          commit('SET_INFO', res.result);
        })
        .catch((err) => {
          pageRes.success = false;
          pageRes.msg = err.message;
        });
      return pageRes;
    },
  },
};
